package com.joplus.housekeeper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.joplus.housekeeper.R;
import com.joplus.housekeeper.bean.PhoneAreaBean;

import java.util.List;

/**
 * author： ccm
 * time： 2017/5/3.
 * description：
 */

public class PhoneAreaAdapter extends BaseAdapter {
    Context mContext;
    List<PhoneAreaBean.DataBean> data;

    public PhoneAreaAdapter(Context mContext, List<PhoneAreaBean.DataBean> data) {
        this.mContext = mContext;
        this.data = data;

    }

    int areaPosition = 0;

    public void setPosition(int position) {
        this.areaPosition = position;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.item_phone_area, null);
        TextView tv = (TextView) inflate.findViewById(R.id.tv1);
        ImageView iv = (ImageView) inflate.findViewById(R.id.iv);
        String s = data.get(position).getName() + " " + data.get(position).getBriefCode() + " " + data.get(position).getCode();
        tv.setText(s);
        if (areaPosition == position) {
            iv.setVisibility(View.VISIBLE);
        } else {
            iv.setVisibility(View.GONE);
        }
        return inflate;
    }
}
